cmake_minimum_required(VERSION 3.5 FATAL_ERROR)

project(recipe-01 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# build 时候才会执行
add_custom_target( unpack-eigen                                                                         # target name
        ALL                                                                                             # 目标将始终被执行
        COMMAND
            ${CMAKE_COMMAND} -E tar zxf ${CMAKE_CURRENT_SOURCE_DIR}/eigen-eigen-5a0156e40feb.tar.gz     # 解压
        COMMAND
            ${CMAKE_COMMAND} -E rename eigen-eigen-5a0156e40feb eigen-3.3.4                             # 重命名
        WORKING_DIRECTORY                                                                               # 上面命令执行的位置
            ${CMAKE_CURRENT_BINARY_DIR}
        COMMENT                                                                                         # message输出
            "Unpacking Eigen3 in ${CMAKE_CURRENT_BINARY_DIR}/eigen-3.3.4"
)

add_executable(linear-algebra linear-algebra.cpp)

add_dependencies(linear-algebra unpack-eigen)               # 由于源文件的编译依赖于Eigen头文件， 需要显式地指定可执行目标对自定义目标的依赖关系
target_include_directories(linear-algebra PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/eigen-3.3.4)              # 源文件使用了#include <Eigen/Dense>